/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.system.rest.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.bo.req.YplyReq;
import me.zhengjie.modules.system.repository.DccYaopinlanyongRepository;
import me.zhengjie.modules.system.service.DccArticleService;
import me.zhengjie.modules.system.service.DccYaopinlanyongService;
import me.zhengjie.modules.system.service.dto.DccArticleQueryCriteria;
import me.zhengjie.modules.system.service.dto.DccYaopinlanyongQueryCriteria;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
* @website https://eladmin.vip
* @author cjl
* @date 2023-05-16
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "DCC文章阅读相关管理")
@RequestMapping("/front/article")
public class FrontArticleController {



    private final DccYaopinlanyongService dccYaopinlanyongService;

    private final DccArticleService dccArticleService;



    @Log("资讯列表")
    @ApiOperation("资讯列表")
    @AnonymousAccess
    @PostMapping(value = "/list")
    public ResponseEntity<Object> queryDccYaopinlanyong(@RequestBody YplyReq yplyReq){
        DccArticleQueryCriteria criteria =new DccArticleQueryCriteria();
        //定义排序规则
//        Sort sort = Sort.by(order,order1);
        Sort sort =Sort.by(Sort.Direction.DESC,"updatedAt");
        Pageable pageable =PageRequest.of(yplyReq.getPage()-1, yplyReq.getSize(),sort);
        Map<String, Object> stringObjectMap = dccArticleService.queryAll(criteria, pageable);
        return new ResponseEntity<>(dccArticleService.queryAll(criteria,pageable),HttpStatus.OK);
    }
}